#include <iostream>
using namespace std;
#define gua(i,a,b) for(int i=(a);i<=(b);++i)
int mp[10005][10005];
int sx[]={1,0,-1,0},sy[]={0,-1,0,1};
int m,n,x,y,ans,mx;
void dg(int a,int b){
    ++ans;mp[a][b]=0;
    gua(i,0,3){
        int xx=a+sx[i],yy=b+sy[i];
        if(mp[xx][yy]==1)dg(xx,yy);
    }
}
int main(){
    cin>>m>>n;
    gua(i,1,m)gua(j,1,n)cin>>mp[i][j];
    gua(i,1,m)gua(j,1,n){
        if(mp[i][j]==1){
            ans=0;
            dg(i,j);
            if(ans>mx)mx=ans;
        }
    }
    cout<<mx<<endl;
    return 0;
}
